import unittest
from dev.stock_visual.email_send import EmailSender

import sys
import os
from pathlib import Path
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)

fileDir = os.path.join(rootPath,"stock_visual/temp")

class EmailSendTest(unittest.TestCase):

    # 发送只带内容的邮件
    def test_send_email_content(self):
        sender = EmailSender(mail_host='smtp.163.com',
                             mail_user="a17603621936",
                             mail_pass="EIJBCYIUMIAXCNYM",
                             sender="a17603621936@163.com")
        # 初始化一封信
        sender.init_email(receivers=['1046474088@qq.com', '2802428220@qq.com'], content="你好，世界", subject="股票分析")
        sender.sendEmail()

    # 发送带文本内容附件的邮件
    def test_send_email_text(self):
        sender = EmailSender(mail_host='smtp.163.com',
                             mail_user="a17603621936",
                             mail_pass="EIJBCYIUMIAXCNYM",
                             sender="a17603621936@163.com")
        # 初始化一封信
        sender.init_email(receivers=['1046474088@qq.com', '2802428220@qq.com'], content="你好，世界", subject="股票分析")
        sender.email_wrapper(filePath=os.path.join(fileDir,'text.txt'),fileType="text")
        sender.sendEmail()

    # 发送带文本内容附件的pdf
    def test_send_email_pdf(self):
        sender = EmailSender(mail_host='smtp.163.com',
                             mail_user="a17603621936",
                             mail_pass="EIJBCYIUMIAXCNYM",
                             sender="a17603621936@163.com")
        # 初始化一封信
        sender.init_email(receivers=['1046474088@qq.com', '2802428220@qq.com'], content="你好，世界", subject="股票分析")
        sender.email_wrapper(filePath=os.path.join(fileDir, 'text.pdf'), fileType="text")
        sender.sendEmail()

    # 发送带html附件的邮件
    def test_send_email_html(self):
        sender = EmailSender(mail_host='smtp.163.com',
                             mail_user="a17603621936",
                             mail_pass="EIJBCYIUMIAXCNYM",
                             sender="a17603621936@163.com")
        # 初始化一封信
        sender.init_email(receivers=['1046474088@qq.com', '2802428220@qq.com'], content="你好，世界", subject="股票分析")
        sender.email_wrapper(filePath=os.path.join(fileDir,'大量数据展示.html'), fileType="html")
        sender.sendEmail()

    # 发送带image附件的邮件
    def test_send_email_image(self):
        sender = EmailSender(mail_host='smtp.163.com',
                             mail_user="a17603621936",
                             mail_pass="EIJBCYIUMIAXCNYM",
                             sender="a17603621936@163.com")
        # 初始化一封信
        sender.init_email(receivers=['1046474088@qq.com', '2802428220@qq.com'], content="你好，世界", subject="股票分析")
        sender.email_wrapper(filePath=os.path.join(fileDir,'temp0.png'), fileType="image")
        sender.sendEmail()